
*****************************************************************************
* INVESTMENT TABLE
*****************************************************************************
clear  
* Load the main regression dataset
use "${dta}\main_regression.dta"

* Create log-transformed investment variable
gen log_inv = log(1 + investment)

* Run the first regression with fixed effects and store the sample
reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 /*
*/  if share > 0.01 & share < ., absorb(orig_dest_year) cluster(apgr_1_num code_entry_num)
gen sample = e(sample)

* Generate investment deciles for further analysis
capture noisily drop q_inv*
egen q_inv = xtile(investment) if share > 0.01 , nq(10)
egen orig_dest_inv = group(apgr_1_num code_entry_num q_inv)

label variable log_inv "log(1+Investment)$\_{\textit{g,t}}$"

* Run regressions including the log of investment
reghdfe buy HC_distance_s_brut_t1 log_inv /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 /*
*/ if share > 0.01, absorb(orig_dest_year) cluster(apgr_1_num code_entry_num)
estimates store inv_1
estadd local ctrl "Yes"
estadd local orig_dest_year "Yes"
estadd local orig_dest_inv "No"
estadd local year "No"

* Run regression with alternative fixed effects
reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 /*
*/ if share > 0.01, absorb(orig_dest_inv year) cluster(apgr_1_num code_entry_num)
estimates store inv_2
estadd local ctrl "Yes"
estadd local orig_dest_year "No"
estadd local orig_dest_inv "Yes"
estadd local year "Yes"

* CAPITAL INTENSITY ANALYSIS
gen log_lk = log(capint_agg)  // Log-transformed capital intensity
capture noisily drop q_kl*
egen q_kl = xtile(capint_agg) if sample, nq(3)  // Create terciles

* Create dummy variables for each tercile and interactions with HC_distance
gen q_kl1 = (q_kl == 1)
gen q_kl2 = (q_kl == 2)
gen q_kl3 = (q_kl == 3)
gen q_kl1_HC = (q_kl == 1) * HC_distance_s_brut_t1
gen q_kl2_HC = (q_kl == 2) * HC_distance_s_brut_t1
gen q_kl3_HC = (q_kl == 3) * HC_distance_s_brut_t1

* Run regressions for each tercile
reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 /*
*/ if sample & q_kl == 1, absorb(orig_dest_year) cluster(apgr_1_num code_entry_num)
estimates store inv_3

reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 /*
*/ if sample & q_kl == 2, absorb(orig_dest_year) cluster(apgr_1_num code_entry_num)
estimates store inv_4

reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 /*
*/ if sample & q_kl == 3, absorb(orig_dest_year) cluster(apgr_1_num code_entry_num)
estimates store inv_5

esttab inv_2 inv_1 inv_3 inv_4 inv_5 using "${export}\investment.tex", /*
*/ keep(HC_distance* log_inv) cells("b(star fmt(%9.3f))" /*
*/ "se(par fmt(%9.3f))") label /*
*/ alignment(D{.}{.}{-1})  /*     
*/ title(results) star(* 0.10 ** 0.05 *** 0.01) substitute(\_ _)/* 
*/ collabels(none) nodepvars compress nomtitles replace booktabs fragment nonumber /*
*/ stats(ctrl orig_dest_year orig_dest_inv year r2_a N, fmt(0 0 0 0 3 %15.0fc) /*
*/ labels(`"Controls"' `"Sector of Origin $\times$ Entry $\times$ Year FE"' `"Sector of Origin $\times$ Entry $\times$ Investment decile FE"' `"Year FE"' `"Adjusted \(R^{2}\)"' `"Observations"') /*
*/ layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" /*
*/ "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}"))


*****************************************************************************
* SECTOR CHARACTERISTICS
*****************************************************************************
* INTERACTIONS: New Firm Creation, Sector Growth, Herfindahl Index, and Survival Probability
* Each section creates terciles, generates dummy variables, and estimates regressions
clear 
use "${dta}\main_regression.dta"

capture noisily drop sample2
reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 /*
*/  if share>0.01 & share <., absorb(apgr_1_num code_entry_num year) cluster(apgr_1_num code_entry_num)
gen sample2 = e(sample)

* INTERACTIONS NEW FIRM CREATION
capture noisily drop q_creation*
egen q_creation = xtile(nombre) if share>0.01 , nq(3)

gen q_creation1 = (q_creation==1)
gen q_creation2 = (q_creation==2)
gen q_creation3 = (q_creation==3)
gen q_creation1_HC = (q_creation==1)*HC_distance_s_brut_t1
gen q_creation2_HC = (q_creation==2)*HC_distance_s_brut_t1
gen q_creation3_HC = (q_creation==3)*HC_distance_s_brut_t1
label variable q_creation2 "2nd tercile of New firms$\_{\textit{n,t-1}}$" 
label variable q_creation3 "3rd tercile of New firms$\_{\textit{n,t-1}}$"
label variable q_creation2_HC "2nd t. New firms$\_{\textit{n,t-1}}\times$ HC Distance$\_{\textit{g,n,t-1}}$" 
label variable q_creation3_HC "3rd t. New firms$\_{\textit{n,t-1}}\times$ HC Distance$\_{\textit{g,n,t-1}}$"  

reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 /*
*/ q_creation2 q_creation3 q_creation2_HC q_creation3_HC /*
*/ if sample2, absorb(apgr_1_num code_entry_num year) cluster(orig_dest_year)
estimates store cross_1
estadd local orig "Yes"
estadd local dest "Yes"
estadd local year "Yes"
estadd local ctrl "Yes"


* INTERACTIONS GROWTH SECTOR
summ  ca,d 
capture noisily drop g_secteur_sales
gen g_secteur_sales = (ca-l1_ca)/l1_ca
summ ca g_secteur_sales,d
winsor2 g_secteur_sales , cut (1 99) replace

capture noisily drop q_ca*
egen q_ca = xtile(g_secteur_sales) if share>0.01, nq(3)

gen q_ca1 = (q_ca==1)
gen q_ca2 = (q_ca==2)
gen q_ca3 = (q_ca==3)
gen q_ca1_HC = (q_ca==1)*HC_distance_s_brut_t1
gen q_ca2_HC = (q_ca==2)*HC_distance_s_brut_t1
gen q_ca3_HC = (q_ca==3)*HC_distance_s_brut_t1
label variable q_ca2 "2nd tercile of Sector growth$\_{\textit{n,t-1}}$" 
label variable q_ca3 "3rd tercile of Sector growth$\_{\textit{n,t-1}}$"
label variable q_ca2_HC "2nd t. Sector growth$\_{\textit{n,t-1}}\times$ HC Distance$\_{\textit{g,n,t-1}}$" 
label variable q_ca3_HC "3rd t. Sector growth$\_{\textit{n,t-1}}\times$ HC Distance$\_{\textit{g,n,t-1}}$"  

reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 /*
*/ q_ca2 q_ca3 q_ca2_HC q_ca3_HC /*
*/ if sample2, absorb(apgr_1_num year) cluster(apgr_1_num year)
estimates store cross_2
estadd local orig "Yes"
estadd local dest "Yes"
estadd local year "Yes"
estadd local ctrl "Yes"

* INTERACTIONS HERFINDHAL INDEX
summ  herfindahl,d 
gen hhi = herfindahl
capture noisily drop q_hhi*
egen q_hhi = xtile(hhi) if share>0.01 , nq(3)

gen q_hhi1 = (q_hhi==1)
gen q_hhi2 = (q_hhi==2)
gen q_hhi3 = (q_hhi==3)
gen q_hhi1_HC = (q_hhi==1)*HC_distance_s_brut_t1
gen q_hhi2_HC = (q_hhi==2)*HC_distance_s_brut_t1
gen q_hhi3_HC = (q_hhi==3)*HC_distance_s_brut_t1
label variable q_hhi2 "2nd tercile of Herfindahl index$\_{\textit{n,t-1}}$" 
label variable q_hhi3 "3rd tercile of Herfindahl index$\_{\textit{n,t-1}}$"
label variable q_hhi2_HC "2nd t. Herfindahl$\_{\textit{n,t-1}}\times$ HC Distance$\_{\textit{g,n,t-1}}$" 
label variable q_hhi3_HC "3rd t. Herfindahl$\_{\textit{n,t-1}}\times$ HC Distance$\_{\textit{g,n,t-1}}$"  

reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 /*
*/ q_hhi2 q_hhi3 q_hhi2_HC q_hhi3_HC /*
*/ if sample2, absorb(apgr_1_num code_entry_num year) cluster(apgr_1_num)
estimates store cross_3
estadd local orig "Yes"
estadd local dest "Yes"
estadd local year "Yes"
estadd local ctrl "Yes"

* INTERACTIONS SURVIVAL
capture noisily drop q_survival*
egen q_survival = xtile(survival) if share>0.01, nq(3)

gen q_survival1 = (q_survival==1)
gen q_survival2 = (q_survival==2)
gen q_survival3 = (q_survival==3)
gen q_survival1_HC = (q_survival==1)*HC_distance_s_brut_t1
gen q_survival2_HC = (q_survival==2)*HC_distance_s_brut_t1
gen q_survival3_HC = (q_survival==3)*HC_distance_s_brut_t1
label variable q_survival2 "2nd tercile of 3-yr Survival probability$\_{\textit{n,t-1}}$" 
label variable q_survival3 "3rd tercile of 3-yr Survival probability$\_{\textit{n,t-1}}$"
label variable q_survival2_HC "2nd t. Survival prob.$\_{\textit{n,t-1}}\times$ HC Distance$\_{\textit{g,n,t-1}}$" 
label variable q_survival3_HC "3rd t. Survival prob.$\_{\textit{n,t-1}}\times$ HC Distance$\_{\textit{g,n,t-1}}$"  

reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 /*
*/ q_survival2 q_survival3 q_survival2_HC q_survival3_HC /*
*/ if sample2, absorb(apgr_1_num code_entry_num year) cluster(orig_dest_year)
estimates store cross_4
estadd local orig "Yes"
estadd local dest "Yes"
estadd local year "Yes"
estadd local ctrl "Yes"



esttab cross_1 cross_4 cross_2 cross_3  using "${export}\cross_sectional.tex", /*
*/ keep(HC_distance* q_* ) cells("b(star fmt(%9.3f))" /*
*/ "se(par fmt(%9.3f))") label /*
*/ alignment(D{.}{.}{-1})  /*     
*/ title(results) star(* 0.10 ** 0.05 *** 0.01) substitute(\_ _)/* 
*/ collabels(none) nodepvars compress nomtitles replace booktabs fragment nonumber /*
*/ stats(ctrl orig dest year r2_a N, fmt(0 0 0 0 3 %15.0fc) /*
*/ labels(`"Controls"' `"Sector of Origin FE"' `"Sector of Entry FE"' `"Year FE"' `"Adjusted \(R^{2}\)"' `"Observations"') /*
*/ layout("\multicolumn{1}{c}{@}"  "\multicolumn{1}{c}{@}"  /*
*/ "\multicolumn{1}{c}{@}"  "\multicolumn{1}{c}{@}" /*
*/ "\multicolumn{1}{c}{@}"  "\multicolumn{1}{c}{@}"))


*****************************************************************************
* INTERACTIONS FINANCIAL CONTRAINTS
*****************************************************************************
clear 
use "${dta}\main_regression.dta"

reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 /*
*/  if share>0.01 & share <., absorb(orig_dest_year) cluster(apgr_1_num code_entry_num)
gen sample = e(sample)

eststo clear

***SIZE
egen q_size = xtile(size_t1) if sample, nq(3)

gen q_size1 = (q_size==1)
gen q_size2 = (q_size==2)
gen q_size3 = (q_size==3)

label variable q_size2 "2nd tercile of N. Workers$\_{\textit{g,t-1}}$" 
label variable q_size3 "3rd tercile of N. Workers$\_{\textit{g,t-1}}$"

gen q_size1_HC = (q_size==1)*HC_distance_s_brut_t1
gen q_size2_HC = (q_size==2)*HC_distance_s_brut_t1
gen q_size3_HC = (q_size==3)*HC_distance_s_brut_t1
label variable q_size2_HC "2nd t. N. Workers$\_{\textit{g,t-1}}\times$ HC Distance$\_{\textit{g,n,t-1}}$" 
label variable q_size3_HC "3rd t. N. Workers$\_{\textit{g,t-1}}\times$ HC Distance$\_{\textit{g,n,t-1}}$"  


***CASH
egen q_cash = xtile(tresact_eff_t1) if sample, nq(3)

gen q_cash1 = (q_cash==1)
gen q_cash2 = (q_cash==2)
gen q_cash3 = (q_cash==3)

label variable q_cash2 "2nd tercile of Cash/N. Workers$\_{\textit{g,t-1}}$" 
label variable q_cash3 "3rd tercile of Cash/N. Workers$\_{\textit{g,t-1}}$"

gen q_cash1_HC = (q_cash==1)*HC_distance_s_brut_t1
gen q_cash2_HC = (q_cash==2)*HC_distance_s_brut_t1
gen q_cash3_HC = (q_cash==3)*HC_distance_s_brut_t1
label variable q_cash2_HC "2nd t. Cash/N. Workers$\_{\textit{g,t-1}}\times$ HC Distance$\_{\textit{g,n,t-1}}$" 
label variable q_cash3_HC "3rd t. Cash/N. Workers$\_{\textit{g,t-1}}\times$ HC Distance$\_{\textit{g,n,t-1}}$"  

***DIVERSIFICATION

label variable diversifie "1(Diversified)$\_{\textit{g,t-1}}$" 

gen q_diversifie_HC = diversifie*HC_distance_s_brut_t1
label variable q_diversifie_HC "1(Diversified)$\_{\textit{g,t-1}}\times$ HC Distance$\_{\textit{g,n,t-1}}$"

***PRIVATE/PUBLIC
label variable listed_gr "1(Public)$\_{\textit{g,t-1}}$" 

gen q_listed_HC = listed_gr*HC_distance_s_brut_t1
label variable q_listed_HC "1(Public)$\_{\textit{g,t-1}}\times$ HC Distance$\_{\textit{g,n,t-1}}$"  

***OLS***
reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 q_size2 q_size3 q_size2_HC q_size3_HC if sample, absorb(orig_dest year) cluster(apgr_1_num code_entry_num) 
estimates store inter_1
estadd local orig_dest "Yes"
estadd local ctrl "Yes"

reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 q_cash2 q_cash3 q_cash2_HC q_cash3_HC if sample, absorb(orig_dest year) cluster(apgr_1_num code_entry_num) 
estimates store inter_2
estadd local orig_dest "Yes"
estadd local ctrl "Yes"

reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 diversifie q_diversifie_HC if sample, absorb(orig_dest year) cluster(apgr_1_num code_entry_num) 
estimates store inter_3
estadd local orig_dest "Yes"
estadd local ctrl "Yes"

reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 listed_gr q_listed_HC if sample, absorb(orig_dest year) cluster(apgr_1_num code_entry_num) 
estimates store inter_4
estadd local orig_dest "Yes"
estadd local ctrl "Yes"

esttab inter_1 inter_2 inter_3 inter_4  using "${export}\interaction2.tex", /*
*/  keep(HC_distance* q_* *diversifie* *listed*) cells("b(star fmt(%9.3f))" /*
*/ "se(par fmt(%9.3f))") label /*
*/   alignment(D{.}{.}{-1})  /*     
*/   title(results) star(* 0.10 ** 0.05 *** 0.01) substitute(\_ _)/* 
*/   collabels(none) nodepvars compress nomtitles replace booktabs fragment nonumber /*
*/ stats(ctrl orig_dest r2_a N, fmt(0 0 3 %15.0fc) /*
*/labels(`"Controls"' `"Sector of Origin $\times$ Entry $\times$ Year FE"' `"Adjusted \(R^{2}\)"' `"Observations"') /*
*/layout("\multicolumn{1}{c}{@}"  "\multicolumn{1}{c}{@}"  "\multicolumn{1}{c}{@}"  "\multicolumn{1}{c}{@}"))



*****************************************************************************
* OTHER DISTANCE MEASURES
*****************************************************************************
clear 
use "${dta}\main_regression.dta"

gen same1_HC = same1*HC_distance_s_brut_t1
gen same2_HC = same2*HC_distance_s_brut_t1

*UPSTREAM
gen upstream01_HC = upstream01*HC_distance_s_brut_t1
gen upstream05_HC = upstream05*HC_distance_s_brut_t1
gen upstream10_HC = upstream10*HC_distance_s_brut_t1
gen upstream20_HC = upstream20*HC_distance_s_brut_t1

*DOWNSTREAM
gen downstream01_HC = downstream01*HC_distance_s_brut_t1
gen downstream05_HC = downstream05*HC_distance_s_brut_t1
gen downstream10_HC = downstream10*HC_distance_s_brut_t1
gen downstream20_HC = downstream20*HC_distance_s_brut_t1

*GEOGRAPHY
label var entree_dep "New area$\_{\textit{g,t}}$" 
label var entree_reg "New area$\_{\textit{g,t}}$"

gen entree_dep_HC = entree_dep*HC_distance_s_brut_t1
gen entree_reg_HC = entree_reg*HC_distance_s_brut_t1

*LABELS
label var entree_dep_HC "New area$\_{\textit{g,t}}\times$ HC Distance$\_{\textit{g,n,t-1}}$" 
label var entree_reg_HC "New area$\_{\textit{g,t}}\times$ HC Distance$\_{\textit{g,n,t-1}}$" 
label var same1 "1(Same 1-digit Industry)$\_{\textit{o,n}}$" 
label var same2 "1(Same 2-digit Industry)$\_{\textit{o,n}}$"
label var upstream05 "$1(Upstream link $>$5\%)$\_{\textit{o,n}}$" 
label var upstream01 "$1(Upstream link $>$1\%)$\_{\textit{o,n}}$" 
label var link_downstream "Downstream link$\_{\textit{o,n}}$"
label var downstream05 "$1(Downstream link $>$5\%)$\_{\textit{o,n}}$" 
label var downstream01 "$1(Downstream link $>$1\%)$\_{\textit{o,n}}$" 
label var entree_dep "1(New department)$\_{\textit{g,t}}$" 
label var entree_reg "1(New region)$\_{\textit{g,t}}$"
label variable diversifie "1(Diversified)$\_{\textit{g,t-1}}$"

*PRODUCT MARKET DISTANCE
rename apgr_1_num apgr
rename code_entry_num apgr_b
merge m:1 apgr apgr_b year using "${input_stata}\distance_bvrs_agg"
drop _merge
rename apgr apgr_1_num
rename apgr_b code_entry_num

rename distance distance_bvrs_agg
gen HC_bvrs = distance_bvrs*HC_distance_s_brut_t1
label var HC_bvrs "PM Distance$\_{\textit{g,n,t-1}}\times$ HC Distance$\_{\textit{g,n,t-1}}$" 
label var distance_bvrs_agg "Product Market Distance$\_{\textit{g,n,t-1}}$" 

*Group FE
egen orig_year = group(apgr_1 year)
egen entry_year = group(code_entry_num year)

capture noisily drop sample
reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 /*
*/  if share>0.01 & share <., absorb(orig_dest year) cluster(apgr_1_num code_entry_num)
gen sample = e(sample)

**************************  REGRESSIONS  ***************************************

reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 entree_dep entree_dep_HC if sample, absorb(orig_dest_year) cluster(apgr_1_num code_entry_num)
estimates store dist_1
estadd local orig "No"
estadd local entry "No"
estadd local orig_dest_year "Yes"
estadd local ctrl "Yes"

replace entree_dep = entree_reg
replace entree_dep_HC = entree_reg_HC

reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 entree_dep entree_dep_HC if sample, absorb(orig_dest_year) cluster(apgr_1_num code_entry_num)
estimates store dist_2
estadd local orig "No"
estadd local entry "No"
estadd local orig_dest_year "Yes"
estadd local ctrl "Yes"

label var same1 "1(Same Industry)$\_{\textit{o,n}}$" 
label var same1_HC "Same Ind.$\_{\textit{o,n}}\times$ HC Distance$\_{\textit{g,n,t-1}}$"

reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 same1 same1_HC if sample, absorb(orig_year entry_year) cluster(apgr_1_num code_entry_num)
estimates store dist_3
estadd local orig "Yes"
estadd local entry "Yes"
estadd local orig_dest_year "No"
estadd local ctrl "Yes"

replace same1 = same2
replace same1_HC = same2_HC

reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 same1 same1_HC if sample, absorb(orig_year entry_year) cluster(apgr_1_num code_entry_num)
estimates store dist_4
estadd local orig "Yes"
estadd local entry "Yes"
estadd local orig_dest_year "No"
estadd local ctrl "Yes"

reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 distance_bvrs if share>0.01& share<., absorb(orig_year entry_year) cluster(apgr_1_num code_entry_num)
estimates store dist_5
estadd local orig "No"
estadd local entry "No"
estadd local orig_dest_year "Yes"
estadd local ctrl "Yes"

reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 distance_bvrs HC_bvrs if share>0.01& share<., absorb(orig_year entry_year) cluster(apgr_1_num code_entry_num) 
estimates store dist_6
estadd local orig "No"
estadd local entry "No"
estadd local orig_dest_year "Yes"
estadd local ctrl "Yes"

label var upstream05 "1(Upstream link)$\_{\textit{o,n}}$" 
label var upstream05_HC "Upstream link$\_{\textit{o,n}}\times$ HC Distance$\_{\textit{g,n,t-1}}$"

reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 upstream05 upstream05_HC if sample&!same2, absorb(orig_year entry_year) cluster(apgr_1_num code_entry_num)
estimates store dist_7
estadd local orig "Yes"
estadd local entry "Yes"
estadd local orig_dest_year "No"
estadd local ctrl "Yes"

replace upstream05 = upstream10
replace upstream05_HC = upstream10_HC

reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 upstream05 upstream05_HC if sample&!same2, absorb(orig_year entry_year) cluster(apgr_1_num code_entry_num)
estimates store dist_8
estadd local orig "Yes"
estadd local entry "Yes"
estadd local orig_dest_year "No"
estadd local ctrl "Yes"

label var downstream05_HC "Downstream link$\_{\textit{o,n}}\times$ HC Distance$\_{\textit{g,n,t-1}}$"
label var downstream05 "1(Downstream link)$\_{\textit{o,n}}$" 

reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 downstream05 downstream05_HC if sample&!same2, absorb(orig_year entry_year) cluster(apgr_1_num code_entry_num)
estimates store dist_9
estadd local orig "Yes"
estadd local entry "Yes"
estadd local orig_dest_year "No"
estadd local ctrl "Yes"

replace downstream05_HC = downstream10_HC
replace downstream05 = downstream10

reghdfe buy HC_distance_s_brut_t1 /*
*/ vaj_eff_t1 diversity_t1 size_t1 immo_eff_t1 sal_eff_t1 tresact_eff_t1 downstream05 downstream05_HC if sample&!same2, absorb(orig_year entry_year) cluster(apgr_1_num code_entry_num)
estimates store dist_10
estadd local orig "Yes"
estadd local entry "Yes"
estadd local orig_dest_year "No"
estadd local ctrl "Yes"


esttab dist_1 dist_2 dist_3 dist_4 dist_5 dist_6 dist_7 dist_8 dist_9 dist_10 using "${export}\distance.tex", /*
*/  keep(HC* distance* upstream* downstream* same* entree*) cells("b(star fmt(%9.3f))" /*
*/ "se(par fmt(%9.3f))") label /*
*/   alignment(D{.}{.}{-1})  /*     
*/   title(results) star(* 0.10 ** 0.05 *** 0.01) substitute(\_ _)/* 
*/   collabels(none) nodepvars compress nomtitles replace booktabs fragment nonumber /*
*/ stats(ctrl orig_dest_year orig entry r2_a N, fmt(0 0 0 0 3 %15.0fc) /*
*/labels(`"Controls"' `"Sector of Origin $\times$ Entry $\times$ Year FE"' `"Sector of Origin $\times$ Year FE"' `"Entry $\times$ Year FE"' `"Adjusted \(R^{2}\)"' `"Observations"') /*
*/layout("\multicolumn{1}{c}{@}"  "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}"  "\multicolumn{1}{c}{@}"  "\multicolumn{1}{c}{@}"))


